/**
 * 
 */
package tani.bnn.com.mbilling.main;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.jxls.exception.ParsePropertyException;
import net.sf.jxls.transformer.XLSTransformer;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;

import tani.bnn.com.mbilling.core.Product;
import tani.bnn.com.mbilling.dao.DailySalePurchaseDAO;
import tani.bnn.com.mbilling.utility.DateUtils;
import tani.bnn.com.mbilling.utility.MBillingConstant;
import tani.bnn.com.mbilling.utility.Utility;

/**
 * @author john
 *
 */
public class GenerateDailyProfitLossReports {
	public static String templateFileName = "templates/dailyProduct.xls";

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		List<Product> products = new ArrayList<Product>();
		try {
			String destFileName = "";
			if(args.length == 0){
				products = new DailySalePurchaseDAO().getAllProductList();
			} else if(args.length == 1){
				products = new DailySalePurchaseDAO().getAllProductList(args[0]);
			}
			destFileName = Utility.getAppUtility().getProperty(MBillingConstant.OUTPUT) 
					+ File.separator + "Daywise_Profit_Loss_Report_" + DateUtils.now(DateUtils.DATE_FILE_FORMAT) + ".xls";
			XLSTransformer transformer = new XLSTransformer();
			Map<String, List<Product>> beans = new HashMap<String, List<Product>>();
			beans.put("products", products);
			//transformer.setColumnPropertyNamesToHide(new String[]{"age"});
			//transformer.setColumnsToHide(new short[]{1});
			transformer.groupCollection("products0.all.name");
			transformer.transformXLS(GenerateDailyProfitLossReports.templateFileName, beans, destFileName);
		} catch (ParsePropertyException e) {
			e.printStackTrace();
		} catch (InvalidFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
